<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Tri-state bus sizing and topology design</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/circuit_design/html/tristate_bus_sizing.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Tri-state bus sizing and topology design</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Section 5.4,  L. Vandenberghe, S. Boyd, and A. El Gamal</span>
<span class="comment">% "Optimizing dominant time constant in RC circuits"</span>
<span class="comment">% Original by Lieven Vandenberghe</span>
<span class="comment">% Adapted for CVX by Joelle Skaf - 11/27/05</span>
<span class="comment">% Modified by Michael Grant - 3/8/06</span>
<span class="comment">%</span>
<span class="comment">% We optimize a tri-state bus connecting six nodes ( The model for the bus</span>
<span class="comment">% is shown in the paper, fig.16). The total wire area is sum_{i&gt;j} lij*xij</span>
<span class="comment">% The bus can be driven from any node. When node i drives the bus, the ith</span>
<span class="comment">% switch is closed and the others are all open. Thus we really have six</span>
<span class="comment">% different circuits, each corresponding to a given node driving the bus.</span>
<span class="comment">% we require that the dominant time constant of each of the six drive</span>
<span class="comment">% configuration circuits has dominant time constant less than Tmax.</span>
<span class="comment">% The problem can be formulated with the following SDP:</span>
<span class="comment">%               minimize        sum_{i&gt;j}(x_ij*l_ij)</span>
<span class="comment">%                   s.t.        0 &lt;= xij &lt;= wmax</span>
<span class="comment">%                               Tmax*(G(x) + GE_kk) - C(x) &gt;= 0 , 1 &lt;=k&lt;= 6</span>
<span class="comment">% The matrix E_kk is zero except for the kth diagonal element, which is 1.</span>

<span class="comment">%</span>
<span class="comment">% Circuit parameters</span>
<span class="comment">%</span>

n=6;         <span class="comment">% number of nodes</span>
m=15;        <span class="comment">% number of wires</span>
beta = 0.5;  <span class="comment">% capacitance per segment is twice beta times xi*li</span>
alpha = 1;   <span class="comment">% conductance per segment is alpha times xi/li</span>
G0 = 1;      <span class="comment">% source conductance</span>
C0 = 10;     <span class="comment">% load capacitor</span>
wmax = 1;    <span class="comment">% upper bound on x</span>

<span class="comment">%</span>
<span class="comment">% Node positions</span>
<span class="comment">%</span>

xpos = [ 0   1   6   8  -4  -1 ;
         0  -1   4  -2   1   4 ] ;
X11 = repmat(xpos(1,:),n,1);
X12 = repmat(xpos(1,:)',1,n);
X21 = repmat(xpos(2,:),n,1);
X22 = repmat(xpos(2,:)',1,n);
LL  = abs(X11-X12) + abs(X21-X22);
L   = tril(LL);
L   = L(L&gt;0);

<span class="comment">%</span>
<span class="comment">% Construct the capacitance and conductance matrices</span>
<span class="comment">%   C(x) = C0 + w11 * C1 + w21 * C2 + ...</span>
<span class="comment">%   G(x) = G0 + w11 * G1 + w21 * G2 + ...</span>
<span class="comment">% and we assemble the coefficient matrices together as follows:</span>
<span class="comment">%   CC = [ C0(:) C1(:) C2(:) ... ]</span>
<span class="comment">%   GG = [ G0(:) G1(:) G2(:) ... ]</span>
<span class="comment">%</span>

CC = zeros(n,n,m+1);
GG = zeros(n,n,m+1);
CC(:,:,1) = C0 * eye(n);
<span class="comment">% segment capacitances and conductances</span>
k3 = 1;
<span class="keyword">for</span> k1 = 1 : 5,
    <span class="keyword">for</span> k2 = k1 + 1 : 6,
        CC([k1,k2],[k1,k2],k3) = beta *[1, 0; 0,1]*L(k3);
        GG([k1,k2],[k1,k2],k3) = alpha*[1,-1;-1,1]/L(k3);
        k3 = k3 + 1;
    <span class="keyword">end</span>
<span class="keyword">end</span>
GG = reshape( GG, n*n, m+1 );
CC = reshape( CC, n*n, m+1 );

<span class="comment">%</span>
<span class="comment">% Compute points the tradeoff curve and the two desired points</span>
<span class="comment">%</span>

<span class="comment">% points on the tradeoff curve</span>
npts    = 50;
delays  = linspace( 410, 2000, npts );
xdelays = [ 410, 2000 ];
xnpts   = length(xdelays);
areas   = zeros(1,npts);
xareas  = zeros(1,xnpts);
sizes   = zeros(m,xnpts);
<span class="keyword">for</span> i = 1 : npts  + xnpts,

    <span class="keyword">if</span> i &gt; npts,
        xi = i - npts;
        delay = xdelays(xi);
        disp( sprintf( <span class="string">'Particular solution %d of %d (Tmax = %g)'</span>, xi, xnpts, delay ) );
    <span class="keyword">else</span>
        delay = delays(i);
        disp( sprintf( <span class="string">'Point %d of %d on the tradeoff curve (Tmax = %g)'</span>, i, npts, delay ) );
    <span class="keyword">end</span>

    <span class="comment">%</span>
    <span class="comment">% Construct and solve the convex model</span>
    <span class="comment">%</span>

    cvx_begin <span class="string">sdp</span> <span class="string">quiet</span>
        variable <span class="string">x(m)</span>
        variable <span class="string">G(n,n)</span> <span class="string">symmetric</span>
        variable <span class="string">C(n,n)</span> <span class="string">symmetric</span>
        minimize( L'*x )
        G == reshape( GG * [ 1 ; x ], n, n );
        C == reshape( CC * [ 1 ; x ], n, n );
        <span class="keyword">for</span> k = 1 : n,
            delay * G - C + sparse(k,k,delay,n,n) &gt;= 0;
        <span class="keyword">end</span>
        0 &lt;= x &lt;= wmax;
    cvx_end

    <span class="keyword">if</span> i &lt;= npts,
        areas(i) = cvx_optval;
    <span class="keyword">else</span>
        xareas(xi) = cvx_optval;
        sizes(:,xi) = x;

        <span class="comment">%</span>
        <span class="comment">% Plot the step response</span>
        <span class="comment">%</span>

        T = linspace(0,2*delay,1000);
        <span class="keyword">for</span> inp = 1 : 6,
            figure(6*xi-5+inp);
            GQ = G + sparse(inp,inp,delay,n,n);
            A = -inv(C)*GQ;
            B = -A*ones(n,1);
            Y = simple_step(A,B,T(2),length(T));
            hold <span class="string">off</span>; plot(T,Y,<span class="string">'-'</span>);  hold <span class="string">on</span>;
            ind=0;
            <span class="keyword">for</span> j=1:size(Y,1),
                ind = max(min(find(Y(j,:)&gt;=0.5)),ind);
            <span class="keyword">end</span>
            tdom   = max(eig(inv(GQ)*C));
            elmore = max(sum((inv(GQ)*C)'));
            tthres = T(ind);
            plot( tdom   * [1;1], [0;1], <span class="string">'--'</span>, <span class="keyword">...</span>
                  elmore * [1;1], [0;1], <span class="string">'--'</span>, <span class="keyword">...</span>
                  tthres * [1;1], [0;1], <span class="string">'--'</span>);
            text(tdom,  0,<span class="string">'d'</span>);
            text(elmore,0,<span class="string">'e'</span>);
            text(tthres,0,<span class="string">'t'</span>);
            ylabel(<span class="string">'Voltage'</span>);
            title(sprintf(<span class="string">'Step response for solution %d, Tmax=%d, with switch %d is closed'</span>,xi,delay,inp));
       <span class="keyword">end</span>

    <span class="keyword">end</span>

<span class="keyword">end</span>;

<span class="comment">%</span>
<span class="comment">% Plot the tradeoff curve</span>
<span class="comment">%</span>

figure(1)
ind = isfinite(areas);
plot(areas(ind), delays(ind));
xlabel(<span class="string">'Area'</span>);
ylabel(<span class="string">'Tdom'</span>);
title(<span class="string">'Area-delay tradeoff curve'</span>);
hold <span class="string">on</span>
<span class="keyword">for</span> k = 1 : xnpts,
    text( xareas(k), xdelays(k), sprintf( <span class="string">'(%d)'</span>, k ) );
<span class="keyword">end</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
Point 1 of 50 on the tradeoff curve (Tmax = 410)
Point 2 of 50 on the tradeoff curve (Tmax = 442.449)
Point 3 of 50 on the tradeoff curve (Tmax = 474.898)
Point 4 of 50 on the tradeoff curve (Tmax = 507.347)
Point 5 of 50 on the tradeoff curve (Tmax = 539.796)
Point 6 of 50 on the tradeoff curve (Tmax = 572.245)
Point 7 of 50 on the tradeoff curve (Tmax = 604.694)
Point 8 of 50 on the tradeoff curve (Tmax = 637.143)
Point 9 of 50 on the tradeoff curve (Tmax = 669.592)
Point 10 of 50 on the tradeoff curve (Tmax = 702.041)
Point 11 of 50 on the tradeoff curve (Tmax = 734.49)
Point 12 of 50 on the tradeoff curve (Tmax = 766.939)
Point 13 of 50 on the tradeoff curve (Tmax = 799.388)
Point 14 of 50 on the tradeoff curve (Tmax = 831.837)
Point 15 of 50 on the tradeoff curve (Tmax = 864.286)
Point 16 of 50 on the tradeoff curve (Tmax = 896.735)
Point 17 of 50 on the tradeoff curve (Tmax = 929.184)
Point 18 of 50 on the tradeoff curve (Tmax = 961.633)
Point 19 of 50 on the tradeoff curve (Tmax = 994.082)
Point 20 of 50 on the tradeoff curve (Tmax = 1026.53)
Point 21 of 50 on the tradeoff curve (Tmax = 1058.98)
Point 22 of 50 on the tradeoff curve (Tmax = 1091.43)
Point 23 of 50 on the tradeoff curve (Tmax = 1123.88)
Point 24 of 50 on the tradeoff curve (Tmax = 1156.33)
Point 25 of 50 on the tradeoff curve (Tmax = 1188.78)
Point 26 of 50 on the tradeoff curve (Tmax = 1221.22)
Point 27 of 50 on the tradeoff curve (Tmax = 1253.67)
Point 28 of 50 on the tradeoff curve (Tmax = 1286.12)
Point 29 of 50 on the tradeoff curve (Tmax = 1318.57)
Point 30 of 50 on the tradeoff curve (Tmax = 1351.02)
Point 31 of 50 on the tradeoff curve (Tmax = 1383.47)
Point 32 of 50 on the tradeoff curve (Tmax = 1415.92)
Point 33 of 50 on the tradeoff curve (Tmax = 1448.37)
Point 34 of 50 on the tradeoff curve (Tmax = 1480.82)
Point 35 of 50 on the tradeoff curve (Tmax = 1513.27)
Point 36 of 50 on the tradeoff curve (Tmax = 1545.71)
Point 37 of 50 on the tradeoff curve (Tmax = 1578.16)
Point 38 of 50 on the tradeoff curve (Tmax = 1610.61)
Point 39 of 50 on the tradeoff curve (Tmax = 1643.06)
Point 40 of 50 on the tradeoff curve (Tmax = 1675.51)
Point 41 of 50 on the tradeoff curve (Tmax = 1707.96)
Point 42 of 50 on the tradeoff curve (Tmax = 1740.41)
Point 43 of 50 on the tradeoff curve (Tmax = 1772.86)
Point 44 of 50 on the tradeoff curve (Tmax = 1805.31)
Point 45 of 50 on the tradeoff curve (Tmax = 1837.76)
Point 46 of 50 on the tradeoff curve (Tmax = 1870.2)
Point 47 of 50 on the tradeoff curve (Tmax = 1902.65)
Point 48 of 50 on the tradeoff curve (Tmax = 1935.1)
Point 49 of 50 on the tradeoff curve (Tmax = 1967.55)
Point 50 of 50 on the tradeoff curve (Tmax = 2000)
Particular solution 1 of 2 (Tmax = 410)
Particular solution 2 of 2 (Tmax = 2000)
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="tristate_bus_sizing__01.png" alt=""> <img src="tristate_bus_sizing__02.png" alt=""> <img src="tristate_bus_sizing__03.png" alt=""> <img src="tristate_bus_sizing__04.png" alt=""> <img src="tristate_bus_sizing__05.png" alt=""> <img src="tristate_bus_sizing__06.png" alt=""> <img src="tristate_bus_sizing__07.png" alt=""> <img src="tristate_bus_sizing__08.png" alt=""> <img src="tristate_bus_sizing__09.png" alt=""> <img src="tristate_bus_sizing__10.png" alt=""> <img src="tristate_bus_sizing__11.png" alt=""> <img src="tristate_bus_sizing__12.png" alt=""> <img src="tristate_bus_sizing__13.png" alt=""> 
</div>
</div>
</body>
</html>